package sv.ues.fia.fragmentcontrol;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class MyFragmentPagerAdapter extends FragmentPagerAdapter {

	final int PAGE_COUNT = 2;	
	private Fragment fragmentPageOne;
	private Fragment fragmentPageTwo;
	private String titlePageOne;
	private String titlePageTwo;

	/** Constructor of the class */
	public MyFragmentPagerAdapter(FragmentManager fMananger,
			Fragment fragmentPageOne, Fragment fragmentPageTwo,
			String titlePageOne, String titlePageTwo) {
		super(fMananger);
		this.fragmentPageOne = fragmentPageOne;
		this.fragmentPageTwo = fragmentPageTwo;
		this.titlePageOne = titlePageOne;
		this.titlePageTwo = titlePageTwo;
	}

	/** This method will be invoked when a page is requested to create */
	@Override
	public Fragment getItem(int arg0) {
		Bundle data = new Bundle();
		data.putInt("current_page", arg0 + 1);
		Fragment fragmentPage;
		if (arg0 == 0) {			
			fragmentPageOne.setArguments(data);
			fragmentPage = fragmentPageOne;
		} else {
			fragmentPageTwo.setArguments(data);
			fragmentPage = fragmentPageTwo;
		}
		return fragmentPage;
	}

	/** Returns the number of pages */
	@Override
	public int getCount() {
		return PAGE_COUNT;
	}

	
	@Override
	public CharSequence getPageTitle(int position) {
		String title;
		if (position == 0) {
			title = titlePageOne;
		} else {
			title = titlePageTwo;
		}
		return title;
	}

}
